﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Gedea.WinForm.Helpers;
using Gedea.Service;
using Gedea.WinForm.Forms.Common;
using Gedea.Service.Services;
using Gedea.Model.Entities;

namespace Gedea.WinForm.Forms.Customers
{
    public partial class New : BaseForm
    {
        public delegate void Deleg1();
        public delegate void Deleg2(Customer customer);

        #region Ctr
        public static New Instance
        {
            get { return ViewLocator<New>.Instance; }
        }

        private New()
        {
            InitializeComponent();
            UserControls.CustomerControl newClient = new UserControls.CustomerControl(new Deleg1(CloseApp), new Deleg2(NewCustomer), false);
            panel1.Controls.Add(newClient);
        }
        #endregion

        private void New_FormClosed(object sender, FormClosedEventArgs e)
        {
            ViewLocator<New>.CloseInstance = null;
        }

        private void CloseApp()
        {
            this.Close();
        }

        private void NewCustomer(Customer customer)
        {
            CustomerService cust = new CustomerService();
            cust.Add(customer);
            MessageBox.Show("El cliente ha sido creado satisfactoriamente");
            this.Close();

        }

    }
}
